package com.ruoyi.squadweb.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.exception.base.BaseException;
import com.ruoyi.common.utils.http.HttpUtils;
import com.ruoyi.squadweb.vo.PlayerVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
//import com.ruoyi.squadweb.mapper.SquadjsAllBanInfoMapper;
import com.ruoyi.squadweb.domain.SquadjsAllBanInfo;
import com.ruoyi.squadweb.service.ISquadjsAllBanInfoService;

/**
 * 广播消息Service业务层处理
 *
 * @author ruoyi
 * @date 2024-03-04
 */
@Service
public class SquadjsAllBanInfoServiceImpl implements ISquadjsAllBanInfoService
{

    /**
     * 查询广播消息
     *
     * @param steamid 广播消息主键
     * @return 广播消息
     */
    @Override
    public SquadjsAllBanInfo selectSquadjsAllBanInfoBySteamid(Long steamid)
    {
        return null;
    }

    /**
     * 查询广播消息列表
     *
     * @param squadjsAllBanInfo 广播消息
     * @return 广播消息
     */
    @Override
    public List<SquadjsAllBanInfo> selectSquadjsAllBanInfoList(SquadjsAllBanInfo squadjsAllBanInfo)
    {
        String data = "";
        if (squadjsAllBanInfo.getSteamid() != null) {
             data = HttpUtils.sendGet("http://119.188.246.63:34841/allbaninfo?steamid=" + squadjsAllBanInfo.getSteamid());
        }
        if (data.length() < 20) {
            throw new BaseException("暂时没有数据");
        }
        //把data转化为josn，并获取list属性
        JSONObject jsonObject = JSON.parseObject(data, JSONObject.class);
        // 将JSON字符串转换为JSONArray对象
        JSONArray jsonArray = JSON.parseArray(jsonObject.getString("list"));
        // 创建一个空的Java List对象
        List<SquadjsAllBanInfo> squadjsAllBanInfos = new ArrayList<>();

        for (int i = 0; i < jsonArray.size(); i++) {
            JSONObject jsonObject1 = jsonArray.getJSONObject(i);
            SquadjsAllBanInfo squadjsAllBanInfoTmp = new SquadjsAllBanInfo();
            squadjsAllBanInfoTmp.setSteamid(jsonObject1.getLong("steamid"));
            squadjsAllBanInfoTmp.setReason(jsonObject1.getString("reason"));
            squadjsAllBanInfoTmp.setOperator(jsonObject1.getString("operator"));
            squadjsAllBanInfoTmp.setEndtime(jsonObject1.getString("endtime"));
            if (squadjsAllBanInfoTmp.getEndtime() == null || "".equals(squadjsAllBanInfoTmp.getEndtime())) {
                squadjsAllBanInfoTmp.setEndtime("永久");
            }
            squadjsAllBanInfoTmp.setTime(jsonObject1.getString("time"));
            squadjsAllBanInfoTmp.setEosid(jsonObject1.getString("eosid"));
            if (squadjsAllBanInfoTmp.getEosid() == null || "".equals(squadjsAllBanInfoTmp.getEosid())) {
                squadjsAllBanInfoTmp.setEosid("N/A");
            }
            squadjsAllBanInfoTmp.setType(jsonObject1.getString("type"));
            squadjsAllBanInfos.add(squadjsAllBanInfoTmp);
        }

        System.out.println(data);
        return squadjsAllBanInfos;
    }

    /**
     * 新增广播消息
     *
     * @param squadjsAllBanInfo 广播消息
     * @return 结果
     */
    @Override
    public int insertSquadjsAllBanInfo(SquadjsAllBanInfo squadjsAllBanInfo)
    {
        return 0;
//        return squadjsAllBanInfoMapper.insertSquadjsAllBanInfo(squadjsAllBanInfo);
    }

    /**
     * 修改广播消息
     *
     * @param squadjsAllBanInfo 广播消息
     * @return 结果
     */
    @Override
    public int updateSquadjsAllBanInfo(SquadjsAllBanInfo squadjsAllBanInfo)
    {
        return 0;
//        return squadjsAllBanInfoMapper.updateSquadjsAllBanInfo(squadjsAllBanInfo);
    }

    /**
     * 批量删除广播消息
     *
     * @param steamids 需要删除的广播消息主键
     * @return 结果
     */
    @Override
    public int deleteSquadjsAllBanInfoBySteamids(Long[] steamids)
    {
        return 0;
//        return squadjsAllBanInfoMapper.deleteSquadjsAllBanInfoBySteamids(steamids);
    }

    /**
     * 删除广播消息信息
     *
     * @param steamid 广播消息主键
     * @return 结果
     */
    @Override
    public int deleteSquadjsAllBanInfoBySteamid(Long steamid)
    {
        return 0;
//        return squadjsAllBanInfoMapper.deleteSquadjsAllBanInfoBySteamid(steamid);
    }
}
